package main

import "fmt"

// 寻找最大回文子串
// https://leetcode.cn/problems/longest-palindromic-substring/
func longestPalindrome(s string) string {
	var temp string
	var longStr string
	var length int

	for i := 0; i < len(s); i++ {
		for j := i + 1; j <= len(s); j++ {
			temp = s[i:j]
			if isOrNohuiwen(temp) {
				if len(temp) > length {
					length = len(temp)
					longStr = temp
				}
			}

		}
	}
	if longStr == "" && len(s) > 0 {
		return s[:1] // 比如输入是 "a" 或者没有回文大于1的，至少返回一个字符
	}
	return longStr
}

func isOrNohuiwen(temp string) bool {
	left := 0
	right := len(temp) - 1
	for left < right {
		if temp[left] != temp[right] {
			return false
		}
		left++
		right--
	}
	return true
}
func main() {
	palindrome := longestPalindrome("babad")
	fmt.Println(palindrome)

}
